feat(asyncpg): Add span streaming support#6215
Conversation
Migrates the asyncpg integration to use `record_sql_queries_supporting_streaming` and `StreamedSpan`, adding support for the `stream` trace lifecycle. Tests are parameterized to cover both static and streaming modes. Fixes PY-2305 Fixes #6003
|
bugbot run |
|
@sentry review |
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 9.83s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 8.16%. Project has 15073 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 31.35% 31.33% -0.02%
==========================================
Files 190 190 —
Lines 21930 21950 +20
Branches 7382 7390 +8
==========================================
+ Hits 6876 6877 +1
- Misses 15054 15073 +19
- Partials 581 581 —Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fd3ee4e. Configure here.
…an has been created. This allows the traces_sampler to see the attributes and make decisions based on them
| with capture_internal_exceptions(): | ||
| add_query_source(span) |
There was a problem hiding this comment.
@sentrivana I realize this code hasn't been touched in 2 years, but since you were the last author - I'm wondering if you can recall why this is sitting outside the record_sql_queries context manager - this looks like it should be sitting within it.
There was a problem hiding this comment.
In the streaming path, for sure, because it sets attributes on the span record_sql_queries creates, and that span needs to still be alive for us to do that.
On the legacy path, it's the other way around, we need the span to be finished (since we use its end timestamp to calculate the duration) to decide whether query source should be attached (because the span is over the configured threshold).

Migrates the asyncpg integration to support the
streamtrace lifecycle.The integration now uses
record_sql_queries_supporting_streamingandStreamedSpanso that DB spans are emitted as soon as they complete rather than being buffered until transaction end.Tests are parameterized over both
span_streaming=Trueandspan_streaming=Falseto verify both paths.Fixes PY-2305, fixes #6003